<%--
 *  File:    DeptEdit.jsp
 *  @Author: Langerwang 
 *  Date:    2001/11/4
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<% //--------------------------------------  setting logger --%>
<%
  	Category cat = Category.getInstance("jsp.DeptEdit"); 
%>



<%
  //init param
  String strModuleName = "OGM";  
  String privilegeCode = "10102,L101";
  String contextPath = request.getContextPath();
  HashMap userInfo = (HashMap)session.getAttribute("userinfo");
  
  boolean bIsEdit = false;
  boolean bIsNewChild = false;
  
  
  //get org info
  
  if(request.getParameter("deptid")!= null)
  {
    bIsEdit = true;
  }
  if(request.getParameter("parentdeptid")!=null)
  {
    bIsNewChild = true;
  }  
%>
<% //--------------------------------------  include files list --%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<html>
<head>
<title></title>
<PageFlow:CheckPageFlow pageName="deptedit"/>
<%@ include file="/inc/CatchError.inc" %>
<%@ include file="/inc/InitEdit.inc" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="../../js/FuncLib.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/PopWindow.js"></script>
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<%
  Vector allstatus = (Vector)pageContext.getAttribute("allstatus");
  HashMap deptInfo = (HashMap)pageContext.getAttribute("deptinfo");
  Integer deptId = null;
  String strDeptCode = new String("");
  String strDeptName = new String("");
  Integer status = null;
  String strDescription = new String("");
  String strBusinessDeptDesc = new String("");
  String strParentDept = new String("");
  Integer strParentDeptId = null;
  Integer orgId = (Integer)userInfo.get("orgid");
  Integer grade = new Integer(1);
  String isBottom = new String("Y");
  if(allstatus == null)
  {
    allstatus = new Vector();
  }
  //get usergroup old info
  if(deptInfo == null || deptInfo.isEmpty())
  {
    deptInfo = new HashMap();
  }  
  else
  {
    deptId = (Integer)deptInfo.get("deptid");
    status = (Integer)deptInfo.get("status");
    strDeptCode = (String)deptInfo.get("deptcode");
    strDeptName = (String)deptInfo.get("deptname");
    strParentDept = (String)deptInfo.get("parentdeptname");
    strParentDeptId = (Integer)deptInfo.get("parentdeptid");
    strDescription = (String)deptInfo.get("deptdesc");
    strBusinessDeptDesc= (String)deptInfo.get("businessdeptdesc");
    orgId = (Integer)deptInfo.get("orgid");
    grade = (Integer)deptInfo.get("grade");
    isBottom = (String)deptInfo.get("isbottom");
  }
  if(bIsNewChild)
  {   
    strParentDept = strDeptName;
    strParentDeptId = deptId;
    grade = new Integer(grade.intValue()+1);
    deptId = null;
    status = null;
    strDeptCode = "";
    strDeptName = "";
    strDescription = "";
    strBusinessDeptDesc="";
    isBottom = "Y";
  }
  cat.debug("The allstatus is :" + allstatus);
  cat.debug("The userGroupInfo is :" + deptInfo); 
%>
</head>

<body>
<script>
function checkInfo(form)
{

  if(isEmpty(form.deptcode.value))
  {
    alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_DeptCode",false))%>");
    return false;
  }
  if(isEmpty(form.deptname.value))
  {
    alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_DeptName2",false) )%>");
    return false;
  }
  return true;
}

function checkStatus(){
  if(depteditform.isbottom.value=="Y"&&depteditform.status.value==28&&depteditform.deptid.value!=""){
  	if(!confirm("将部门状态置为无效时，此部门所维护产品分组也会变为无效，是否确定继续！")){
  		depteditform.status.value = 41;
  		return;
  	}
  }
}

function page_done()
{
  if(!checkForm(document.depteditform))return;
  if(!checkInfo(document.depteditform))
  {
    return;
  }

  if(!checkNull(document.depteditform))
  		return;
  emptyToNull(document.depteditform);
  depteditform.target = "_parent";
  document.depteditform.actionname.value = "done";
  isRunning = true;
  document.depteditform.submit();
}
function popcostcenter(){

window.open("<%=contextPath%>/fim/ma/LiabilityCenterPop.jsp?<%= OvalTools.randomURL() %>&orgid=<custom:write name="userinfo" property="orgid" scope="session"/>" , "newwindow", "height=250, width=600, top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");

}
function page_setresponsecenter(id,code,name){
 depteditform.responsecenterid.value=id;
 depteditform.responsecode.value=code;
 depteditform.responsename.value=name;

}
 function reloadresponsecenter()
 {
    if (depteditform.responsecode.value==""){
    depteditform.responsecenterid.value="";
    depteditform.responsename.value="";
    return;
    }
   depteditform.responsecenterid.value="";
 page_handleRequest('<%=JspHelper.filterNull(request.getContextPath())%>',depteditform);

}

function page_handleResponse()
{
	depteditform.responsecenterid.value=getResponseData('responsecenterid');
	depteditform.responsecode.value = getResponseData('responsecode');
	depteditform.responsename.value = getResponseData('responsename');
}

function page_selectDepartmentPrdGroup(){
    window.open("ZylProductGroupFrm.jsp?<%= OvalTools.randomURL() %>&departmentid="+document.depteditform.deptid.value+"&isbottom="+document.depteditform.isbottom.value);
}

</script>
<iframe id="reloadHandler" name="reloadHandler" style="display:none"></iframe>
<table width="100%" cellspacing="0" border="0" cellpadding="0">
  <tr>
    <td>
      <table width="100%" cellspacing="0" cellpadding="0">

        <tr>
          <td colspan="2" class="summary_top"></td>
        </tr>
        <tr>
          <td colspan="2"><img src="../../images/<%= strLanguageCode %>/quote.gif" width="16" height="11">
            <%= label.getLabelName("L_NEDepartment") %></td>
        </tr>
      </table>
      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
      <form name="depteditform" method="post" action="../../Dispatcher" >
        <input type="hidden" name="orgid" value="<%=JspHelper.filterNull( request.getParameter("orgid") )%>">
        <input type="hidden" name="grade" value="<%=JspHelper.filterNull(grade)%>">
            <input type="hidden" name="schema" value="ovdepartment">
            <input type="hidden" name="qlname" value="selectcostcenterforreload">
		    <input type="hidden" name="datelastupdated" value="<%=JspHelper.filterNull( new java.sql.Date(new java.util.Date().getTime()) )%>">
		    <input type="hidden" name="pagename" value="deptedit">
		    <input type="hidden" name="actionname">
		    <input type="hidden" name="successflag">
		    <input type="hidden" name="deptid" value="<%=JspHelper.filterNull(deptId)%>">
		    <input type="hidden" name="isbottom" value="<%=JspHelper.filterNull(isBottom)%>">
		    <input type="hidden" name="languagecode" value="<%=strLanguageCode%>">

		     <%if(bIsNewChild){%>
			      <input type="hidden" name="parentdeptid" value="<%=JspHelper.filterNull(strParentDeptId)%>">
			   <%}%>
		   
        <tr>
          <td class="need" width="110">&nbsp;<%= label.getLabelName("L_DeptCode") %><%= label.getLabelName("L_Colon") %></td>
          <td> 
          <%if(!bIsEdit){%>
            <input type="text" name="deptcode" size="15" value="<%=JspHelper.filterNull(strDeptCode)%>">
          <%}else{%>  
            <input type="text" name="deptcode" readonly="true" size="15" value="<%=JspHelper.filterNull(strDeptCode)%>">
          <%}%> 
          </td>
        </tr>
        <tr> 
          <td class="need" width="110">&nbsp;<%= label.getLabelName("L_DeptName2") %><%= label.getLabelName("L_Colon") %></td>
          <td>
            <input type="text" name="deptname" size="15" value="<%=JspHelper.filterNull(strDeptName)%>">
          </td>
        </tr>

        <%if(bIsNewChild){%>
        <tr height='12'> 
          <td class="td-text" width="110">&nbsp;<%= label.getLabelName("L_ParentDept") %><%= label.getLabelName("L_Colon") %></td>
          <td>
			      <%=JspHelper.filterNull(strParentDept)%>&nbsp;
          </td>
        </tr>
         <%}%>
         
        <%if(!bIsNewChild){%>
	        <tr height='12'> 
	          <td class="td-text" width="110">&nbsp;<%= label.getLabelName("L_ParentDept") %><%= label.getLabelName("L_Colon") %></td>
	          <td>
			       <custom:select property="parentdeptid" name="deptinfo" optionsName="alldeptnames"
							optionValueKey="deptid" optionInnerTextKey="deptname" defaultValue="--------"/>
			  </td>
	        </tr>
        <%}%>
        <tr>
          <td class="td-text" width="110">&nbsp;<%= label.getLabelName("L_ProductGroup") %><%= label.getLabelName("L_Colon") %></td>
          <td>
            <%if(JspHelper.filterNull(deptId).equals("")||status.intValue()==28){ %>
              &nbsp;
            <%}else {%>
              <a onclick="javascript:page_selectDepartmentPrdGroup();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
            <% }%>
          </td>
        </tr>
		<!-- 
          <tr>
          <td class="td-text" width="110">&nbsp;<%= label.getLabelName("L_OwnerCostCenterma") %><%= label.getLabelName("L_Colon") %></td>
          <td>
          <custom:text name="deptinfo" property="responsecode" onblur="reloadresponsecenter();"/>
             <a onclick='javascript:popcostcenter();'><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
             &nbsp;<custom:text name="deptinfo" property="responsename" readonly="true"/>
            <custom:hidden name="deptinfo" property="responsecenterid" />


          </td>
        </tr>
		 -->
        <tr>
          <td class="td-text" width="110">&nbsp;<%= label.getLabelName("L_DeptDesc") %><%= label.getLabelName("L_Colon") %></td>
          <td> 
            <input type="text" name="deptdesc" size="70" value="<%=JspHelper.filterNull(strDescription)%>">
          </td>
        </tr>
        <tr> 
          <td class="td-text" width="110">&nbsp;<%= label.getLabelName("L_BusinessDeptName") %><%= label.getLabelName("L_Colon") %></td>
          <td>
            <input type="text" name="businessdeptdesc" size="70" value="<%=JspHelper.filterNull(strBusinessDeptDesc)%>">
          </td>
        </tr>
        <tr> 
          <td class="need" width="110">&nbsp;<%= label.getLabelName("L_StatusName") %><%= label.getLabelName("L_Colon") %></td>
          <td> 
            <select name="status" onchange="checkStatus();">
            <logic:iterate id="statuses" collection="<%= allstatus%>">
            <% 
              HashMap mapStatus = (HashMap)pageContext.getAttribute("statuses"); 
              cat.debug("mapStatus is " + mapStatus);
              String strSelect = "";
              if(((Integer)mapStatus.get("statuscode")).equals(status))
              {
                strSelect = "Selected";
              }                              
            %>
              <option <%=JspHelper.filterNull( strSelect )%>  value = "<%=JspHelper.filterNull( mapStatus.get("statuscode") )%>">
              <%=JspHelper.filterNull( mapStatus.get("statusname") )%>
              </option>
            </logic:iterate>
        </select>
          </td>
        </tr>
         <%if(!bIsNewChild){%>
         <tr height='12'> 
	          <td class="need" width="110">&nbsp;<%= label.getLabelName("L_Service_Attribute") %><%= label.getLabelName("L_Colon") %></td>
	          <td>
	          <%  if("Y".equals(isBottom)){ %>
			       <custom:selectdic property="servicetype"
					dictType="ServiceAttribute" name="deptinfo"
					label="L_Service_Attribute" command="notnull" defaultValueCost=" "
					defaultValue="--------" />
		      <%}else{ %>
		           &nbsp;<custom:write property="servicetype" dictType="ServiceAttribute" name="deptinfo"/>
		      <%} %>
			  </td>
	     </tr>
	     <% 
	     }%>
	     <%if(bIsNewChild){%>
	        <tr height='12'> 
	          <td class="need" width="110">&nbsp;<%= label.getLabelName("L_Service_Attribute") %><%= label.getLabelName("L_Colon") %></td>
	          <td>
			       <custom:selectdic property="servicetype"
					dictType="ServiceAttribute" 
					label="L_Service_Attribute" command="notnull" defaultValueCost=" "
					defaultValue="--------" />
			  </td>
	     </tr>
	     <%} %>
        <!--  
        <tr>
          <td class="td-text" width="110">&nbsp;<%= label.getLabelName("L_GLGroupCode") %><%= label.getLabelName("L_Colon") %></td>
          <td>
            <custom:selectdic name="deptinfo" property="glgroupcode" dictType="GLGroupCode"  defaultValue="----"/>
          </td>
        </tr>   
        -->           
      </table>
      </form>
    </td>
  </tr>
  <tr>
    <td class="summary_top"></td>
  </tr>
  <tr>
    <td class="td_center">
    <a onclick="page_done()"><custom:button type="1" label="L_Finish" imgsrc="finish.gif" border="0" style="width:60"/></a>
    </td>
  </tr>
</table>
</body>
</html>


